;input variables required; [dth] [pth] [zth] [hth] [dminth]
;outputs; [body]
;
;thread drill
{Set:[ddrill]={Math:[dth]-[pth]}}
{If:[adrill]=Nothing}
	{Set:[adrill]=30}
{EndIf:}
_Polyline _PersistentClose=_No 0,0,[hdrill] _Mode=_Line 0,[ddrill]/2,[hdrill] 0,[ddrill]/2,-[hdrill] 0,0,-[hdrill]-(tan([adrill]d)*([ddrill]/2)) _Enter
_SelLast
{Revolve:0,0,0:0,0,-[hth]}
_Move 0,0,0 0,0,[zth]
{Set:[drill]={SelectedObjs}}
_SelNone
;
;simplified thread?
{If:[sel_th]=Simplified}
	{If:[allth]=True}
		_Line 0,[dth]/2,0 0,[dth]/2,-[hth]
	{EndIf:}
	{If:[allth]<>True}
		_Polyline _PersistentClose=_No 0,[dth]/2,0 _Mode=_Line 0,[dth]/2,-[hth] 0,[ddrill]/2,-[hth]-(tan([adrill]d)*([pth]/2)) _Enter
	{EndIf:}
	_SelLast
	{Revolve:0,0,0:0,0,-[hth]}
	_Move 0,0,0 0,0,[zth]
	;
	{SetName:[npth]}
	{Set:[thread]={SelectedObjs}}
	_SelNone
{EndIf:}
;
;detailed thread?
{If:[sel_th]=Detailed}
	{If:[allth]=True}
		{Set:[hth]={Math:[hth]*2}}
	{EndIf:}
	;
	;thread spiral
	_Spiral 0,0,-[hth] 0,0,[hdrill] _Mode=_Pitch _Pitch [pth] 0,[dth]/2,-[hth] 0,[dth]/2,[hdrill] _Enter
	_SelLast
	{Set:[spiral]={SelectedObjs}}
	_SelNone
	;
	;thread sections
	{Set:[SectionID]={Guid}}
	{Set:[val]={Math:(([dth]-[dminth])/2)+([tol]*2)}}
	_Polyline _PersistentClose=_No 0,[dth]/2,-[hth]+([pth]/16) _Mode=_Line 0,([dth]/2)-[val],-[hth]+([pth]/16)+(tan(30d)*[val]) 0,([dth]/2)-[val],-[hth]-([pth]/16)-(tan(30d)*[val]) 0,[dth]/2,-[hth]-([pth]/16) _Close
	_SelLast
	{Set:[section]={SelectedObjs}}
	_Copy _InPlace
	_SelNone
	_SelLast
	_Move 0,0,0 0,-[pth]/2,0
	-_Properties _Object _Name [SectionID] _Enter _Enter
	_SelNone
	_SelID [section]
	_-Properties _Object _Name [SectionID] _Enter _Enter
	_Move 0,0,0 0,0,[pth]
	_Copy _InPlace
	_SelNone
	_SelLast
	{Set:[val]={Math:int(([hth]+[hdrill])/[pth])-1}}
	_Move 0,0,-[hth] {Math:[val]*[pth]} 0,0,0
	_SelNone
	-_Sweep1 '_SelID [spiral] '-_SelName [SectionID] _Enter _Natural _Enter _Style=_Roadlike 0,0,-[hth] 0,0,[hth] _Simplify=_None _Closed=_No _ShapeBlending=_Local _Enter
	_SelLast
	_Move 0,0,0 0,0,[zth]
	{Cap:[tol]}
	_SelID [drill]
	{BooleanUnion:[tol]}
	{Set:[drill]={SelectedObjs}}
	_SelNone
	_SelID [spiral]
	_Delete
	-_SelName [SectionID]
	_Delete
{EndIf:}
;
_SelID [body]
_SelID [drill]
{BooleanDifference:[tol]:[body]:[drill]}
{Set:[body]={SelectedObjs}}
_SelNone